<template>
  <div class="account-create-wrap">
    <createTop firstMenu="商品管理" secondMenu="商品分类" :title="pageName"></createTop>

    <el-card shadow="always" v-loading="loading">
      <div class="content">
        <div class="se">
          <div class="content-title">名称 <span class="red-icon">※</span></div>
          <el-input :style="{'width':'350px'}" v-model="className" placeholder="请输入名称"></el-input>
        </div>
        <div class="se">
          <div class="content-title">编号 <span class="red-icon">※</span></div>
          <el-input :style="{'width':'350px'}" align="left" v-model="number" placeholder="请输入编号"></el-input>
        </div>

      </div>
      <div class="content">
        <div class="se">
          <div class="content-title shoter">权重</div>
          <div class="tip">(数字越大,越靠前,不设置按修改时间排序)</div>
          <el-input :style="{'width':'350px'}" v-model="order" :rows="5" resize="none" placeholder="请输入权重"></el-input>
        </div>
      </div>
      <saveBtn @confirm="confirm"></saveBtn>
    </el-card>
  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import createTop from '@/components/createTop.vue';
import saveBtn from '@/components/saveBtn.vue';
import ajaxResquest from '@/api/apiRequest';

@Component({
  components: {
    createTop,
    saveBtn
  }
})
export default class ProduceCategoryCreate extends Vue {
  pageName: string = '';
  secondMenu: string = '';
  
  // rolesRes!: ajaxResquest;
  createRes!: ajaxResquest;
  infoRes!: ajaxResquest;

  roles: any[] = [];
  role: string = '';
  className: string = '';
  number: string = '';
  order: string = '';
  loading: boolean = false;
  checkList: any[] = [];
  id!: string;
  mounted() {
    if (this.$route.query.edit) {
      this.pageName = '编辑分类';
      this.id = this.$route.query.id;
      this.infoRes = new ajaxResquest('/goods/getClassInfo');
      this.getInfo();
    } else {
      this.pageName = '新增分类';
    }
    this.createRes = new ajaxResquest('/goods/classToDo');
  }
  getInfo(): void {
    this.infoRes.getFunction({ class_id: this.id }).then((res: any) => {
      if (res.data.code === 1) {
        this.className = res.data.data.types.class_name;
        this.number = res.data.data.types.number;
        this.order = res.data.data.types.order;
      }
    });
  }
  confirm(): void {
    if (this.className == '' || this.number == '') {
      this.$message.error('参数不能为空');
      return;
    }
    let data: any = {
      className: this.className,
      number: this.number,
      order: this.order
    };
    if (this.$route.query.id) {
      data = { ...data, classId: this.$route.query.id };
    }
    this.createRes.getFunction(data).then((res:any) => {
      if (res.data.code === 1) {
        this.$to('produceCategory');
      }
    });
  }
}
</script>
<style lang="less">
.account-create-wrap {
  height: 100%;
  padding: 15px;
  display: flex;
  flex-direction: column;
  z-index: 101;
  box-sizing: border-box;
  .el-card {
    overflow-y: auto;
  }
  .content {
    font-size: 16px;
    background-color: #fff;
    border-radius: 4px;
    .content-title {
      width: 30%;
      height: 40px;
      margin-top: 20px;
      line-height: 2;
      text-align: left;
    }
    .short-input {
      width: 100%;
      width: 240px;
      margin-right: 10px;
    }
    .el-upload-list__item {
      width: 350px;
    }
    .el-textarea {
      margin-bottom: 30px;
    }
  }
  .checkbox {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
  }
  .el-checkbox {
    margin: 2px 0 !important;
    width: 130px;
  }
}
</style>
